package com.itheima.demo1;

public class Demo22 {
    public static void main(String[] args) {
        System.out.println(-3 >> 1);
        System.out.println(3 >> 1);
        int a = 20;
        int b = 10;
        a = a ^ b;
        b = a ^ b;
        a = a ^ b;
        System.out.println(a + "  ---  " + b);

//      实现数组元素交换
        int[] arr = {1, 2, 3, 4, 5};
        for (int i = 0; i < arr.length / 2; i++) {
            arr[i] = arr[i] ^ arr[arr.length - 1 - i];
            arr[arr.length - 1 - i] = arr[i] ^ arr[arr.length - 1 - i];
            arr[i] = arr[i] ^ arr[arr.length - 1 - i];
        }

//      优化
        int[] arr1 = {5, 4, 3, 2, 1};
        for (int start = 0, end = arr1.length - 1; start < end; start++, end--) {
            arr1[start] = arr1[start] ^ arr1[end];
            arr1[end] = arr1[start] ^ arr1[end];
            arr1[start] = arr1[start] ^ arr1[end];
        }

//      输出
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr1[i] + " ");
        }
    }
}
